package dale.web.essay.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import dale.web.common.page.*;
import dale.web.essay.model.Essay;
import dale.web.essay.repository.EssayRepository;

@Service
public class EssayServiceImpl implements EssayService {

	private EssayRepository repository;

	@Autowired
	public EssayServiceImpl(EssayRepository repository) {
		this.repository = repository;
	}

	public Essay detail(Integer no) {
		return repository.select(no);
	}

	public List<Essay> search(Essay item, int nowPage, int blockSize) {
		if (nowPage == 0)
			nowPage = 1;
		int startRow = PageUtils.getStartRow(nowPage, blockSize);
		return repository.select(item, startRow, blockSize);
	}

	public List<Essay> search(Essay item, int nowPage) {
		return search(item, nowPage, 10);
	}

	public Pager page(Essay item, int nowPage, int blockSize,
			int blockPage) {
		int rowTotal = repository.count(item);
		return new Pager(nowPage, rowTotal, blockSize, blockPage);
	}

	public Pager page(Essay item, int nowPage) {
		int rowTotal = repository.count(item);
		return new Pager(nowPage, rowTotal);
	}

	public List<Essay> search(Essay item) {
		return repository.select(item);
	}

	public int create(Essay item) {
		return repository.insert(item);
	}

	public int modify(Essay item) {
		return repository.update(item);
	}

	public int remove(Integer no) {
		return repository.delete(no);
	}

}
